package com.zhentao.exception;

import com.zhentao.until.ResponseResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

@ControllerAdvice
@RestController
public class GlobaExceptionHandler {



    //全局异常
@ExceptionHandler(BusinessException.class)
public ResponseResult e5(BusinessException e){
    return ResponseResult.errorResult(e.getCode(), e.getMsg());
}


    //空指针异常


    @ExceptionHandler(NullPointerException.class)
    public ResponseResult nullPointerException(NullPointerException e){
        return ResponseResult.errorResult(101, "空指针异常");
    }

    //处理算数异常
    @ExceptionHandler(ArithmeticException.class)
    public ResponseResult arithmetic(ArithmeticException e){
        return ResponseResult.errorResult(102, "算数异常");
    }
}
